package com.example.framework2002.http;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class Http {
    private Http(){}
    private volatile static Http http;
    public synchronized static Http getInstance(){
        if (http==null){
            http=new Http();
        }
        return http;
    }

    private Retrofit retrofit;

    public Retrofit getRetrofit() {
        if (retrofit==null){
            onse();
        }
        return retrofit;
    }

    private void onse() {
        OkHttpClient client = new OkHttpClient.Builder()
                .readTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60,TimeUnit.SECONDS)
                .build();
        retrofit=new Retrofit.Builder()
                .client(client)
                .baseUrl("http://www.fenghongzhang.com:9999")
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
    }
}
